package com.example.bio;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.util.concurrent.TimeUnit;

/**
 * @Description
 * @Author 26233
 * @Create 2021-10-27 16:25:19
 */

public class SocketClient {

    public static void main(String[] args) throws IOException {

        String hostName = "192.168.101.8";
        int port = 8888;
        Socket clientSocket = null;
        try {
            clientSocket = new Socket(hostName, port);
            InputStream inputStream = clientSocket.getInputStream();
            OutputStream outputStream = clientSocket.getOutputStream();

            outputStream.write("ok".getBytes());
            System.out.println("ok");
//
//            byte[] recv = new byte[1024];
//            int read = inputStream.read(recv);
//            System.out.println("read = " + read);

//            outputStream.write("ok".getBytes());
//            System.out.println("ok");

            TimeUnit.SECONDS.sleep(1000);

        }catch (Exception e){
            e.printStackTrace();
        }finally {
            if (clientSocket != null){
                clientSocket.close();
            }
        }

    }

}
